﻿using Jt808CommandEncoder.Utils;
using System;
using System.Collections.Generic;

namespace Jt808CommandEncoder
{
    public class CommandEncoder
    {
        /// <summary>
        /// Set Device Parameters (0x8103)
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameters"></param>
        /// <returns>hex string</returns>
        public static string setDeviceParameterForHex(string deviceId, int msgFlowId, Dictionary<Int32,Object> dicParameters) {
            return PackageUtil.packageHexCommand(deviceId, msgFlowId,0x8103, dicParameters);
        }

        /// <summary>
        /// Set Device Parameters (0x8103)
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameters"></param>
        /// <returns>byte[]</returns>
        public static byte[] setDeviceParameterForBytes(string deviceId, int msgFlowId, Dictionary<Int32, Object> dicParameters)
        {
            return PackageUtil.packageBytesCommand(deviceId, msgFlowId, 0x8103, dicParameters);
        }

        /// <summary>
        /// Query Device Parameter (0x8104)
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <returns>hex string</returns>
        public static string queryDeviceParameterForHex(string deviceId, int msgFlowId)
        {
            return PackageUtil.packageHexCommand(deviceId, msgFlowId, 0x8104, null);
        }

        /// <summary>
        /// Query Device Parameter (0x8104)
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <returns>byte[]</returns>
        public static byte[] queryDeviceParameterForBytes(string deviceId, int msgFlowId)
        {
            return PackageUtil.packageBytesCommand(deviceId, msgFlowId, 0x8104, null);
        }

        /// <summary>
        /// device control(0x8105) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>hex string</returns>
        public static string deviceControlCommandForHex(string deviceId, int msgFlowId, Dictionary<int, Object> dicParameter)
        {
            return PackageUtil.packageHexCommand(deviceId, msgFlowId, 0x8105, dicParameter);
        }

        /// <summary>
        /// device control(0x8105) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>byte[]</returns>
        public static byte[] deviceControlCommandForBytes(string deviceId, int msgFlowId, Dictionary<int, Object> dicParameter)
        {
            return PackageUtil.packageBytesCommand(deviceId, msgFlowId, 0x8105, dicParameter);
        }


        /// <summary>
        /// Downlink Transparent Transmission (0x8900) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>hex string</returns>
        public static string transparentCommandForHex(string deviceId, int msgFlowId, Dictionary<int, string> dicParameter)
        {
            return PackageUtil.packageHexCommand(deviceId, msgFlowId, 0x8900, dicParameter);
        }

        /// <summary>
        /// Downlink Transparent Transmission (0x8900) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>byte[]</returns>
        public static byte[] transparentCommandForBytes(string deviceId, int msgFlowId, Dictionary<int, string> dicParameter)
        {
            return PackageUtil.packageBytesCommand(deviceId, msgFlowId, 0x8900, dicParameter);
        }

        /// <summary>
        /// Platform RSA Public Key (0x8A00) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>hex string</returns>
        public static string platformRSAPublicKeyCommandForHex(string deviceId, int msgFlowId, Dictionary<Int32, byte[]> dicParameter)
        {
            return PackageUtil.packageHexCommand(deviceId, msgFlowId, 0x8A00, dicParameter);
        }

        /// <summary>
        /// Platform RSA Public Key (0x8A00) command message
        /// </summary>
        /// <param name="deviceId"></param>
        /// <param name="msgFlowId"></param>
        /// <param name="dicParameter"></param>
        /// <returns>byte[]</returns>
        public static byte[] platformRSAPublicKeyCommandForBytes(string deviceId, int msgFlowId, Dictionary<Int32, byte[]> dicParameter)
        {
            return PackageUtil.packageBytesCommand(deviceId, msgFlowId, 0x8A00, dicParameter);
        }
    }
}
